// merchantCenter.js
const app = getApp()
var util = require("../../utils/util.js")
Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperbox: app.globalData.swiperbox,
    swiper: app.globalData.swiper,

    balance: '0.0',
    todayAmount: '0',
    todayTime: "--:--",
    timePre: '',
    grid: [
      {
        name: '收益总计',
        txt: '¥0'
      }, {
        name: '设备总数',
        txt: '0'
      }, {
        name: '订单总数',
        txt: '0'
      },
    ],

    memu: [
      {
        icon: 'icon-dianpuguanli',
        title: '店铺管理',
        url: '../../pages/merchantManage/merchantManage'
      }, {
        icon:'icon-navicon-srtj',
        title: '收入统计',
        url: '../../pages/proxyIncome/proxyIncome?userType=shop'
      }
    ]
  },


  withdraw: function () {
    var balance = this.data.balance;
    wx.navigateTo({
      url: '../../pages/proxyWithdraw/proxyWithdraw?balance=' + balance,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var date = util.formatTime(new Date);
    var timePre = Number(date.substring(11, 13) * 60) + Number(date.substring(14, 16))
    that.setData({
      userInfo: app.globalData.userInfo,
      swiper: wx.getStorageSync('swiper') || app.globalData.swiper,
      todayTime: date.substring(11, 16),
      timePre: timePre,
    })
    var data = {};
    app.post("shop/shopIndex", data).then((res) => {
      if (res.code == 200) {
        var data = res.data;
        var deviceCount = 'grid[1].txt';
        var orderCount = 'grid[2].txt';
        var cumulative = 'grid[0].txt'
        that.setData({
          [deviceCount]: data.deviceCount,
          [orderCount]: data.orderCount,
          todayAmount: data.todayAmount,
          [cumulative]: "￥"+data.account.cumulative,
          balance: data.account.balance
        })
      }
    }).catch((errMsg) => {
      console.log(errMsg);//错误提示信息
    })
  },
  onShow: function () {
    // this.onLoad();
  },
})